package com.example.administrator.commonlibrary.wholehelper;

import com.example.administrator.commonlibrary.bean.DaoSession;
import com.example.administrator.commonlibrary.bean.GreedaoBean;
import com.example.administrator.commonlibrary.bean.GreedaoBeanDao;
import com.example.administrator.commonlibrary.thirdparty.GreendaoConfig;
import com.example.administrator.commonlibrary.utils.LogUtil;

import java.util.List;

import javax.inject.Inject;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/13
 * 描述：数据库储存的帮助类
 */
public class GreendaoHelper {

    private DaoSession daoSession;
    public GreendaoHelper(GreendaoConfig config){
        this.daoSession=config.getDaoSession();
        LogUtil.d(config.toString()+"---HuadongActivity--");
    }
    public List<GreedaoBean> getMusicList() {
        GreedaoBeanDao musicHistoryDao = daoSession.getGreedaoBeanDao();
        List<GreedaoBean> list = musicHistoryDao.queryBuilder().orderDesc(GreedaoBeanDao.Properties.MId).list();
        return list;
    }

    public  void getDelete(){
        GreedaoBeanDao musicHistoryDao = daoSession.getGreedaoBeanDao();
        musicHistoryDao.deleteAll();
    }

    public  boolean getIsEmpty(){
        GreedaoBeanDao musicHistoryDao = daoSession.getGreedaoBeanDao();
        long count = musicHistoryDao.queryBuilder().buildCount().count();
        return count==0 ? true:false;
    }

    public  void setInster(GreedaoBean musicHistory){
        GreedaoBeanDao musicHistoryDao = daoSession.getGreedaoBeanDao();
        long count = musicHistoryDao.queryBuilder().where(GreedaoBeanDao.Properties.MId.eq(musicHistory.getMId())).buildCount().count();
        if (count==0){
            musicHistoryDao.insert(musicHistory);
        }
    }

}
